# Maintainer: James Ross-Gowan <rossymiles@gmail.com>

pkgbase=protobuf
pkgname=('protobuf' 'protobuf-devel')
pkgver=3.12.4
pkgrel=1
pkgdesc="Protocol Buffers - Google's data interchange format"
arch=('i686' 'x86_64')
url='https://developers.google.com/protocol-buffers/'
groups=('libraries')
license=('BSD')
depends=('gcc-libs' 'zlib')
makedepends=('zlib-devel')
source=(protobuf-${pkgver}.tar.gz::https://github.com/google/protobuf/archive/v${pkgver}.tar.gz)
sha256sums=('512e5a674bf31f8b7928a64d8adf73ee67b8fe88339ad29adaa3b84dbaa570d8')
noextract=("protobuf-${pkgver}.tar.gz")

prepare() {
  [[ -d ${srcdir}/protobuf-${pkgver} ]] && rm -rf ${srcdir}/protobuf-${pkgver}
  tar -xzf "${srcdir}/protobuf-${pkgver}.tar.gz"

  cd  ${srcdir}/protobuf-${pkgver}
  ./autogen.sh
}

build() {
  cd "${srcdir}/protobuf-${pkgver}"

  ./configure \
    --host=${CHOST} \
    --prefix=/usr
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/protobuf-${pkgver}"
  make check
}

package_protobuf() {
  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.dll "${pkgdir}/usr/bin/"
  install -Dm644 "${srcdir}/protobuf-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_protobuf-devel() {
  pkgdesc="Protobuf headers and libraries"
  groups=('development')
  depends=("protobuf=${pkgver}")

  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.exe "${pkgdir}/usr/bin/"
  cp -rf "${srcdir}/dest/usr/include" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/lib" "${pkgdir}/usr/"
}
